package com.up.interview.redis;

/**
 * @author: liuchengjun
 * @title: CacheValue
 * @projectName: 海联技术中台V2.0
 * @depart 软件事业部
 * @description:
 * @date: 2025/10/20/周一 11:26 (星期一)
 * @since V2.0
 */
public class CacheValue {
    private static final long serialVersionUID = 1L;

    private Object data;
    private long createTime;
    private long expireTime;

    public CacheValue() {
        this.createTime = System.currentTimeMillis();
    }

    public CacheValue(Object data) {
        this.data = data;
        this.createTime = System.currentTimeMillis();
    }

    public CacheValue(Object data, long expireSeconds) {
        this.data = data;
        this.createTime = System.currentTimeMillis();
        this.expireTime = expireSeconds > 0 ? createTime + expireSeconds * 1000 : 0;
    }
    public boolean isExpired() {
        return expireTime > 0 && System.currentTimeMillis() > expireTime;
    }

    // Getters and Setters
    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public long getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(long expireTime) {
        this.expireTime = expireTime;
    }
}
